﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Kevin.Controls;
using DevExpress.XtraEditors;

namespace Kevin.WindosControls.Test
{
    public partial class Form1 : Form
    {
        
        public Form1()
        {
            InitializeComponent();
            
            this.dataBind1.DataBindItems.Add(new DataBindItem() { PropertyName="Age", TargetControl=this.txtAge, BindDirection=BindDirection.Both });
            this.dataBind1.DataBindItems.Add(new DataBindItem() { PropertyName = "Name", TargetControl = this.txtName, BindDirection = BindDirection.Both });
            this.dataBind1.DataBindItems.Add(new DataBindItem() { PropertyName = "Value", TargetControl = this.txtValue, BindDirection = BindDirection.Both });
            this.dataBind1.DataBindItems.Add(new DataBindItem() { PropertyName = "Sex", TargetControl = this.cbSex, BindDirection = BindDirection.Both, ControlPropertyName = "SelectedText" });

            this.dataBind1.Data = new Person();
            //this.propertyGrid1.SelectedObject = this.dataBind1;
            webBrowser1.Navigate("www.csddd.ccds");

            APTSClient.APTSServiceClient Service = new APTSClient.APTSServiceClient();
            int recordCount = 0;
            DataTable dt = Service.GetData(out recordCount, "", "select * from Tb_General where codename like :test and code_key =:tts", 10, 1, new object[] { "%鱼%" });
        }

        

        private void btnC2D_Click(object sender, EventArgs e)
        {
           
            Person entity = new Person();
            entity = (Person)this.dataBind1.Data;
            if (this.dataBind1.ValidateSuccess)
            {

            }
            else
            {
                MessageBox.Show("数据校验失败！");
            }
            string sql=entity.Insert().ToString();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            
        }

        private void btnD2C_Click(object sender, EventArgs e)
        {
            Person entity = new Person() { Age = 111, Name = "Test", Value="testValue" };
            this.dataBind1.Data = entity;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            DevExpress.LookAndFeel.UserLookAndFeel.Default.SetSkinStyle("Office 2010 Blue");

            XtraForm1 frm = new XtraForm1();
            frm.Text = "数据动态载入测试"+new Random().Next(100).ToString();
            _CurrentForm = frm;
            frm.Show();
        }

        static XtraForm _CurrentForm;

        public  XtraForm CurrentForm
        {
            get { return _CurrentForm; }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            //MessageBox.Show(CurrentForm.Text);
            this.layoutControl1.SaveLayoutToXml("test" + new Random().Next(999999) + ".xml");
            System.IO.MemoryStream st=new System.IO.MemoryStream();
            this.layoutControl1.SaveLayoutToStream(st);
            string strLayout=Encoding.UTF8.GetString(st.ToArray());

        }

        public static void RigisterCurrentForm(XtraForm form)
        {
            _CurrentForm = form;
        }
        
    }
}
